﻿using HardcoreGame.Content.Buffs;
using Terraria;
using Terraria.DataStructures;
using Terraria.ModLoader;
using Terraria.ModLoader.IO;

namespace HardcoreGame.Common.Players
{
    public class HungerPlayer : ModPlayer
    {
        public int CounterForHunger;
        public int StageForHunger = 1;
        public override void SaveData(TagCompound tag)
        {
            tag["StageForHunger"] = StageForHunger;
            tag["CounterForHunger"] = CounterForHunger;
        }
        public override void LoadData(TagCompound tag)
        {
            StageForHunger = tag.GetInt("StageForHunger");
            CounterForHunger = tag.GetInt("CounterForHunger");
        }
        public override void PostUpdate()
        {

            if (Player.creativeGodMode)
            {
                StageForHunger = 1;
            }
            if (StageForHunger < 1)
            {
                StageForHunger = 1;
            }
            if (CounterForHunger == 0)
            {
                CounterForHunger = Main.masterMode ? 3530 * 2 : 5295 * 2;
            }
            if (CounterForHunger > 0)
            {
                CounterForHunger--;
                if (CounterForHunger == 0)
                {
                    CounterForHunger = Main.masterMode ? 3530 * 2 : 5295 * 2;
                    if (StageForHunger != 10)
                    {
                        StageForHunger += 1;
                    }
                }
            }

        }
        public override void Kill(double damage, int hitDirection, bool pvp, PlayerDeathReason damageSource)
        {

            StageForHunger = 1;
            CounterForHunger = Main.masterMode ? 3530 * 2 : 5295 * 2;
        }

        public override void PostUpdateBuffs()
        {

            switch (StageForHunger)
            {
                case 10 when Player.whoAmI == Main.myPlayer:
                    Player.AddBuff(ModContent.BuffType<Hunger>(), 2);
                    break;
                case < 10 when Player.whoAmI == Main.myPlayer:
                    Player.ClearBuff(ModContent.BuffType<Hunger>());
                    break;
            }
        }

    }
}